---
title: "NYC Restaurant Inspections in Staten Island"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```
```{r clean_data}
data(rest_inspec)
rest_inspec <-
rest_inspec %>%
select(boro, critical_flag, cuisine_description, score, grade) %>%
filter(boro == "STATEN ISLAND",
!is.na(grade),
!str_detect(cuisine_description, "[Ww]ater|[Jj]uice|[Cc]offee")) %>%
mutate(cuisine_description = recode(cuisine_description, "Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin"))
```
Column {data-width=650}
-----------------------------------------------------------------------
### Distribution of inspection scores by cuisine type
```{r boxplot}
rest_inspec %>%
mutate(cuisine_description = fct_reorder(cuisine_description, score)) %>%
plot_ly(y = ~score, color = ~cuisine_description, type = "box", colors = "viridis")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Distribution of scores received by all restaurants
```{r histogram}
rest_inspec %>%
plot_ly(x = ~score, type = "histogram")
```
### The number of critical vs not critical by grade
```{r bar}
crit_bygrade <-
rest_inspec %>%
filter(critical_flag != "Not Applicable",
grade %in% c("A", "B", "C")) %>%
group_by(grade, critical_flag) %>%
count() %>%
ungroup() %>%
pivot_wider(names_from = critical_flag,
values_from = n)
crit_bygrade %>%
plot_ly(x = ~grade, y = ~`Not Critical`, type = "bar", name = "Not Critical") %>%
add_trace(y = ~Critical, name = "Critical") %>%
layout(yaxis = list(title = 'count'), barmode = 'stack')
```